package com.example.esredisrabbitmqdemo.controller;

import com.example.esredisrabbitmqdemo.pojo.User;
import com.example.esredisrabbitmqdemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: es-redis-rabbitmq-demo
 * @BelongsPackage: com.example.esredisrabbitmqdemo.controller
 * @Author: 江岸
 * @CreateTime: 2020-07-04 16:09
 * @Description:
 */
@RestController
@Api(tags = "UserController",description = "用户表现层")
public class UserController {
    @Autowired
    private UserService userService;


    @ApiOperation(value = "添加用户")
    @PostMapping("add")
    public String add(User user){
        String add = userService.add(user);
        return add;
    }

    @ApiOperation(value = "通过id查找用户")
    @PostMapping("queryById")
    public User queryById(int id){
        User user = userService.queryById(id);
        return user;
    }

    @ApiOperation(value = "通过id修改用户")
    @PostMapping("updateById")
    public String updateById(User user){
        String update = userService.update(user);
        return update;
    }

    @ApiOperation(value = "删除用户")
    @PostMapping("deleteById")
    public String deleteById(int id){
        String delete = userService.delete(id);
        return delete;
    }

    @ApiOperation(value = "查询所有")
    @PostMapping("findAll")
    public List<User> findAll(){
        List<User> all = userService.findAll();
        return all;
    }

    @ApiOperation(value = "模糊查询")
    @PostMapping("likeSearch")
    public List<User> likeSearch(String info){
        List<User> users = userService.likeSearch(info);
        return users;
    }

}
